#!/usr/bin/env python
# -*- coding: utf-8 -*-

#generate the highligt card 

import pygtk
pygtk.require('2.0')
import gtk.gdk

BLACK, RED = range(2)


def transform(in_fn, type, out_ftype, out_fn):
    pixbuf = gtk.gdk.pixbuf_new_from_file(in_fn);
    drawable = gtk.gdk.Pixmap(width=pixbuf.get_width(), height=pixbuf.get_height(), depth=24);
    gc = drawable.new_gc()
    hl_gc = drawable.new_gc()
    func = None
    if type is BLACK:
        func = gtk.gdk.INVERT
    else:
        func = gtk.gdk.XOR
    hl_gc.set_function(func)
    drawable.draw_pixbuf(gc, pixbuf)
    dw, dh = drawable.get_size()
    drawable.draw_rectangle(hl_gc, True, 0, 0, dw, dh)
    out_pbuf = gtk.gdk.Pixbuf.get_from_drawable(drawable)
    out_pbuf.save(out_fn, out_ftype)


if __name__ == '__main__':
    in_fn = './cards/card_1.gif'
    type = BLACK
    out_ftype = 'gif'
    out_fn = 'card_1_hl.gif'
    transform(in_fn, type, out_ftype, out_fn)
